import sys
import re

	
if len(sys.argv)<2:
     print("usage:")
     exit(0)

myfile = open(sys.argv[1], "r")
fmt=''
synopsis=''
comments=[]
ll=[]
l=[]
for i in range(0,256):
	ll.append([i,fmt,synopsis,comments])

for line in (myfile):
	if len(line)==0:
		continue
	if line.startswith('#'):
		continue
	if line.startswith('\t\t'):
		c=2				
	elif line.startswith('\t'):
		c=1
	else:
		c=0
			
	s=line.strip(' \t\n')
	
	if c==0:
		s1=s.split('\t')
		#print(s1)
		s2=s1[0].split(' ')	
		#print(s2)				
		fmt=s2[1]
		synopsis=s1[1]
		comments=s1[2:]					
		if s2[0].find('..')!=-1:
			start=s2[0][0:2]
			end=s2[0][4:6]
			#print(start)
			#print(end)
			for i in range(int(start,16),int(end,16)+1):
				#print(i)
				#print(comments)
				ll[i]=[i,fmt,synopsis,comments]						
		else:
			i=int(s2[0],16)
			ll[i][2]=synopsis
			if ll[i][1]=='':
				ll[i][1]=fmt
			if len(ll[i][3])==0:
				ll[i][3]=comments						
	elif c==2:
		#s2=[]
		comments.append(s)
	else:
		s1=s.split(':',1)
		s2=s1[1].split('\t')
		#print(s1)	
		#print(s2)		
		if len(s2)>1:
			comments=comments+s2[1:]
		synopsis=s2[0]
		i=int(s1[0],16)
		ll[i][2]=synopsis
		if ll[i][1]=='':
			ll[i][1]=fmt
		if len(ll[i][3])==0:
			ll[i][3]=comments	

print('''

#ifndef dalvik_do_h
#define dalvik_do_h

#include "dalvik.h"


struct _vm_state;

typedef struct _vm_state *PVMSTATE;

''')

for x in ll:
	x2=x[2].strip('" ')
	x1=x2.split(' ',1)
	if len(x1)>0:
		m=x1[0]
	else:
		m= x2

	if m=='(unused)':
		continue
	mm=m.replace('/','_').replace('-','_')
	print( 'void do_%s(PVMSTATE p_vm,PINSN_INFO p_insn);'%(mm))



print('''


#endif// dalvik_do_h
''')
